package com.keshan.controller;

import com.auth0.jwt.interfaces.DecodedJWT;
import com.keshan.pojo.*;
import com.keshan.service.*;
import com.keshan.utils.JWTUtils;
import com.keshan.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author keshan
 * @date 2022/10/23 - 12:58
 */
//@CrossOrigin 解决跨域
@CrossOrigin
@Controller
@RequestMapping("/multiclass")
public class MulticlassController {
    @Autowired
    BloodOxygenServices bloodOxygenServices;
    @Autowired
    BloodPressureServices bloodPressureServices;
    @Autowired
    HeartrateServices heartrateServices;
    @Autowired
    SleepServices sleepServices;
    @Autowired
    StepCountServices stepCountServices;
    @Autowired
    UserDeviceServices userDeviceServices;

    /**
     * 主要数据获取今日
     * @param
     * @return
     */
    //多类查询通过imei
    @RequestMapping("/multiclasslisthidetoday")
    @ResponseBody
    public Msg selectMulticlassListHideByImeiToday(HttpServletRequest httpServletRequest){
        String token = httpServletRequest.getHeader("token");
        System.out.println(token);
        try {
            DecodedJWT decodedJWT = JWTUtils.verifyAndInfo(token);
            String username = decodedJWT.getClaim("username").asString();
            List<BloodOxygenHide> bloodOxygenHideList = bloodOxygenServices.getBloodOxygenListHideByUsernameToday(username);
            List<BloodPressureHide> bloodPressureHideList = bloodPressureServices.getBloodPressureListHideByUsernameToday(username);
            List<HeartrateHide> heartrateHideList = heartrateServices.getHeartrateListHideByUsernameToday(username);
            List<SleepHide> sleepHideList = sleepServices.getSleepListHideByUsernameToday(username);
            List<StepCountHide> stepCountHideList = stepCountServices.getStepCountListHideByUsernameToday(username);
            return Msg.success().add("bloodOxygenList",bloodOxygenHideList).add("bloodPressureList",bloodPressureHideList)
                    .add("heartrateList",heartrateHideList).add("sleepList",sleepHideList)
                    .add("stepCountList",stepCountHideList);
        } catch (Exception e) {
            e.printStackTrace();
            return Msg.fail().add("error", e.getMessage());
        }
    }
}
